package com.frame.verify;

import com.frame.utils.StringUtil;

public class Length implements IParamVerify {

	@Override
	public VerifyResult verify(Object value, String p, String msg) {

        String val = null==value?"":String.valueOf(value);
		msg = StringUtil.isBlank(msg)? "参数长度错误，长度应为: "+p: msg;
		String[] lens = p.split(":");
		int minLen = StringUtil.isBlank(lens[0])? Integer.MIN_VALUE: Integer.valueOf(lens[0]);
		int maxLen = (lens.length<2 || StringUtil.isBlank(lens[1]))? Integer.MAX_VALUE: Integer.valueOf(lens[1]);

		return new VerifyResult((val.length()>=minLen && val.length()<=maxLen), msg);
	}
}
